import Vue from 'vue'
import Router from 'vue-router'
import { constantRoutes } from "./modules";
import remainingRouter from "@/router/modules/remaining"
Vue.use(Router)

const createRouter = () => new Router({
  scrollBehavior(to, from, savedPosition) {
    return new Promise(resolve => {
      if (savedPosition) {
        return savedPosition;
      } else {
        if (from.meta.saveSrollTop) {
          const top =
          document.documentElement.scrollTop || document.body.scrollTop;
          resolve({ left: 0, top });
        }
      }
    });
  },
  routes: constantRoutes.concat(...remainingRouter),
  strict: true,
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
